package com.fenger.bus.service.impl;

import com.fenger.bus.domain.Customer;
import com.fenger.bus.mapper.CustomerMapper;
import com.fenger.bus.service.CustomerService;
import com.fenger.bus.vo.CustomerVo;
import com.fenger.sys.contast.SysConstast;
import com.fenger.sys.utils.DataGirdView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;

    @Override
    @Transactional(readOnly = true)
    public DataGirdView queryAllCustomer(CustomerVo customerVo) {
        Page<Object> page = PageHelper.startPage(customerVo.getPage(), customerVo.getLimit());
        List<Customer> customers = this.customerMapper.queryAllCustomer(customerVo);

        return new DataGirdView(SysConstast.SUCCESS_CODE,SysConstast.SUCCESS_MSG,page.getTotal(),customers);
    }

    @Override
    public void addCustomer(CustomerVo customerVo) {
        this.customerMapper.insertSelective(customerVo);
    }

    @Override
    public void updateCustomer(CustomerVo customerVo) {
        this.customerMapper.updateByPrimaryKeySelective(customerVo);
    }

    @Override
    public void deleteCustomer(Integer id) {
        this.customerMapper.deleteByPrimaryKey(id);
    }
}
